
const MyPromise = require('./MyPromise')

let promise = new MyPromise((resolve, reject) => {
  setTimeout(() => {
    resolve("setTimeout")
  }, 2000)
  // resolve('success');
  // reject('err');
})

function other () {
  return new MyPromise((resolve, reject) => {
    resolve("other")
  })
}

function other2 () {
  return new MyPromise((resolve, reject) => {
    resolve("other2")
  })
}

// promise.then(value => {
//   console.log('resolve', value)
//   // throw new Error("then error");
//   return other();
// }, reason => {
//   console.log('reject', reason)
//   return 1000;
// }).then(value => {
//   console.log(value);
// }, reason => {
//   console.log(reason);
// })

// all方法的逻辑
// 1. all 参数必须是个数组, 数组中可以放置 `普通值` 或 `Promise 对象`.
// 2. all 中的所有方法都成功, 最终结果才是成功, 只要有一个方法是失败, 则 all 方法的结果就是失败
MyPromise.all(['a', 'b', other(), other2(), 'e']).then(value => console.log(value))
